package com.wx.mall.sys.controller;


import com.alibaba.fastjson.JSON;
import com.wx.mall.common.ResultVo;
import com.wx.mall.common.exception.code.BaseResponseCode;
import com.wx.mall.common.utils.DataResult;
import com.wx.mall.sys.entity.VerificationCode;
import com.wx.mall.sys.service.IVerificationCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author j
 * @since 2020-03-20
 */
@RestController
@RequestMapping("/verification-code")
@Api(tags = "验证码设置接口")
@Slf4j
public class VerificationCodeController {

    @Autowired
    private IVerificationCodeService iVerificationCodeService;

    @ApiOperation("查询验证码设置")
    @GetMapping("/get")
    public String get(){
        return JSON.toJSONString(new DataResult(BaseResponseCode.SUCCESS.getCode(),"",iVerificationCodeService.get()));
    }

    @ApiOperation("保存验证码设置")
    @PostMapping("/save")
    public String save(@ApiParam("启动验证码") String enableVerification,
                       @ApiParam("登录失败时显示验证码") String loginFailure,
                       @ApiParam("验证码方式") String verificationCode2,
                       @ApiParam("图形验证码宽度") String graphicsWidth,
                       @ApiParam("图形验证码高度") String graphicsHeight,
                       @ApiParam("图形验证码内容大小") String graphicsContent,
                       @ApiParam("图形验证码位数") String graphicsNum) {
        VerificationCode verificationCode = new VerificationCode();
        verificationCode.setEnableVerification(enableVerification);
        verificationCode.setLoginFailure(loginFailure);
        verificationCode.setVerificationCode(verificationCode2);
        verificationCode.setGraphicsWidth(graphicsWidth);
        verificationCode.setGraphicsHeight(graphicsHeight);
        verificationCode.setGraphicsContent(graphicsContent);
        verificationCode.setGraphicsNum(graphicsNum);
        iVerificationCodeService.save2(verificationCode);
        return JSON.toJSONString(new DataResult(BaseResponseCode.SUCCESS.getCode(),"提交成功！",""));
    }

}

